<%@page import="com.bill.common.system.dto.RuleDTO"%>
<%@page import="com.bill.common.system.service.IRuleService"%>
<%@page import="com.sinba.common.dto.PageDTO"%>
<%@page import="com.bill.common.system.dto.ExtractDTO"%>
<%@page import="com.bill.common.system.dto.TransactionRecordDTO"%>
<%@page import="com.bill.common.system.service.ITransactionRecordService"%>
<%@page import="com.bill.common.system.service.IExtractService"%>
<%@page import="com.bill.common.user.dto.AccountDTO"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="com.bill.common.user.entity.Account"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@page import="com.bill.common.user.service.IAccountService"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ include file="../language.jsp" %>
<%
	if(session.getAttribute("password2")==null){
	response.sendRedirect( "login2.jsp?pageUrl=user/cashBusiness.jsp");
	return;
	}
	ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	
	ExtractDTO qdto = new ExtractDTO(); 
	qdto.setLoginName((String)session.getAttribute("loginName"));
	qdto.setParentAccount((String)session.getAttribute("loginName"));
	IExtractService extractService = (IExtractService)ac.getBean("extractService");
	int pages = 1;
	if(request.getParameter("pages")!=null && request.getParameter("_pages")!=""){
		pages = Integer.parseInt(request.getParameter("pages"));
	}
	int rows = 10;
	int start = ( pages - 1 ) * rows;
	PageDTO pageDTO = extractService.findPager(qdto,start,rows,"desc","createTime");
	pageDTO.setPage( pages );
	pageDTO.setRows( rows );
	request.setAttribute("pageDTO",pageDTO);
	
	
	//可提现余额
	ITransactionRecordService transactionRecordService = (ITransactionRecordService)ac.getBean("transactionRecordService");
	Double txbalance1 = transactionRecordService.findUserBalance(session.getAttribute("loginName").toString(),"Dynamic");
	
	request.setAttribute("txbalance1",txbalance1);
	
	
	IRuleService ruleService = (IRuleService)ac.getBean("ruleService");
	RuleDTO ruleDTO = ruleService.findRuleInfo();
	request.setAttribute("ruleDTO",ruleDTO);
	
	request.setAttribute("pageUrl","cashBusiness.jsp?");
	
%>
<fmt:setLocale value="${empty cookie['language'].value?'zh_CN':cookie['language'].value}"/>
	<fmt:setBundle basename="i18n.itilbase"/>
	<c:set var="lang" value="${empty cookie['language'].value?'zh_CN':cookie['language'].value}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title><fmt:message key="i18n.salesTotal"/>-<fmt:message key="i18n.title"/> </title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1" />
	
	<link rel="shortcut icon" href="../index/favicon.png" />
	
	<!-- bootstrap -->
    <link href="css/bootstrap/bootstrap.css" rel="stylesheet" />
    <link href="css/bootstrap/bootstrap-responsive.css" rel="stylesheet" />
    <link href="css/bootstrap/bootstrap-overrides.css" type="text/css" rel="stylesheet" />

    <!-- global styles -->
    <link rel="stylesheet" type="text/css" href="css/elements.css" />
    <link rel="stylesheet" type="text/css" href="css/icons.css" />
    
	 <!-- this page specific styles -->
    <link rel="stylesheet" href="css/compiled/tables.css" type="text/css" media="screen" />
    
	<link rel="stylesheet" href="../styles/myStyle.css" />
</head>
<body>
	<!-- main container -->
	<div class="content container-fluid">
		<!-- BreadcrumbNavigation -->
        <div class="row-fluid head">
            <div class="span12">
                <h4>财务管理 &gt; 账户提现</h4>
            </div>
        </div>
        <!-- End BreadcrumbNavigation -->
        <!-- list table -->
        <div class="table-wrapper orders-table section">
        	<div class="row-fluid head">
                <div class="span12">
                    <p class="tableTopTip">
                    	<fmt:message key="i18n.dyBalance"/>：${txbalance1}
                    	<c:if test="${not empty ruleDTO.rule010}">
							&nbsp;&nbsp;&nbsp;&nbsp;(<fmt:message key="i18n.zhuyi"/>：${ruleDTO.rule010 })
						</c:if>
					</p>
                </div>
            </div>
			<form id="cashBusinessForm" action="registerUser!userOpt.action" method="post" >
				<input type="hidden" name="optType" value="TingXiangApply" />
		 		<input type="hidden" name="extractDTO.loginName" value="${session.loginName }" />
				<input type="hidden" name="pageUrl" value="cashBusiness.jsp" />
				<input type="hidden" value="${txbalance1 }" id="cashbussiness_balance1" />
				<input type="hidden" value="${txbalance2 }" id="cashbussiness_balance2" />
		 		<div class="row-fluid filter-block">
	                <div class="pull-left">
	                	<div>
	                		 <fmt:message key="i18n.accountBag"/>:
                             <select  id="dtype" name="extractDTO.dtype" class="tx_contBoxR2_1">
								<option value="Dynamic"><fmt:message key="i18n.dyAccount"/></option>
								<%-- <option value="Static"><fmt:message key="i18n.jtAccount"/></option> --%>
							</select>
                        </div>
                        <div>
                        	<fmt:message key="i18n.txMoney"/>:
							<input type="tel" name="extractDTO.tixiangSum" value="100" id="extractMoney" />
						</div>
						<div>
							<c:if test="${not empty session.activationTime}">
		                   		<a class="btn-flat success new-product" href="javascript:tingXiangApply()" ><fmt:message key="i18n.txApply"/></a>
		                    </c:if>
	                    </div>
	                </div>
	            </div>
			</form>
			
			<div class="row-fluid">
				<table class="table table-hover">
					<thead>
						<tr>
				        	<th><fmt:message key="i18n.userbianhao"/></th>
		       				<th><fmt:message key="i18n.txMoney"/></th>
		       				<th><fmt:message key="TiXianShouXuFei"/></th>
		       				<th>实际到账</th>
		       				<th><fmt:message key="i18n.applyDate"/></th>
		       				<th><fmt:message key="i18n.acceptDate"/></th>
		       				<th><fmt:message key="i18n.acceptStatus"/></th>
		       				<th><fmt:message key="i18n.remark"/></th>
						</tr>
					</thead>
                    <tbody>
						<c:forEach items="${pageDTO.data}" var="data">
						<tr>
		   					<td>${data.loginName }</td>
							<td>${data.tixiangSum }</td>
							<td>${data.poundage }</td>
							<td>${data.tixiangSum-data.poundage }</td>
							<td><fmt:formatDate value="${data.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
							<td><fmt:formatDate value="${data.handTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
							<td>${data.status}</td>
							<td>
							${data.formAccountStr}(${data.remark})
							</td>
		   				</tr>
			   			</c:forEach>
						<c:if test="${empty pageDTO.data}">
						<tr>
							<td colspan="8" style="text-align: center;"><fmt:message key="i18n.noData"/></td>
						</tr>
						</c:if> 
                    </tbody>
				</table>
			</div>
			<div class="pagination">
				<ul>
		            <li><a href="${pageUrl }&pages=${pageDTO.page-1}">&#8249;</a></li>
		            <li><a <c:if test="${pageDTO.page eq 1}"> class="active" </c:if> href="${pageUrl }&pages=1">1</a></li>
		            <c:if test="${pageDTO.total ge 2}">
		            <li><a <c:if test="${pageDTO.page eq 2}"> class="active" </c:if> href="${pageUrl }&pages=2">2</a></li>
		            </c:if>
		            <c:if test="${pageDTO.total ge 3}">
		            <li><a <c:if test="${pageDTO.page eq 3}"> class="active" </c:if> href="${pageUrl }&pages=3">3</a></li>
		            </c:if>
		            <c:if test="${pageDTO.total ge 4}">
		            <li><a <c:if test="${pageDTO.page eq 4}"> class="active" </c:if> href="${pageUrl }&pages=4">4</a></li>
		            </c:if>
		            <li><span style="font-size: 10px;"> ${pageDTO.page}/${pageDTO.total} | <fmt:message key="i18n.total"/>${pageDTO.totalSize} </span></li>
		            <li><a href="${pageUrl }&pages=${pageDTO.page+1}">&#8250;</a></li>
		            
		            
	          	</ul>
	          	
	        </div>
		</div>
        <!-- end list table -->
        
    </div>
    
    <script type="text/javascript" src="../scripts/jquery/jquery-1.4.2.min.js"></script>
    
	<script>
	$(function(){
		var _result = '${param.result}';
		if(_result=='TixiangSumGeBalance'){
			alert('The withdrawal amount is greater than can(提现金额大于可提现金额)!');
			window.location.href="cashBusiness.jsp";
		}else if(_result=='ApplyLoginNameNotExist'){
			alert('Apply for membership does not exist(申请的会员不存在)!');
			window.location.href="cashBusiness.jsp";
		}else if(_result=='Success'){
			alert('Successful applicants will be accepted as soon as possible, the financial(申请成功，财务会尽快受理)!');
			window.location.href="cashBusiness.jsp";
		}
	})
	
	function tingXiangApply(){
		var extractMoney = $('#extractMoney').val();
		if(extractMoney==null || extractMoney==''){
			alert('请输入提现金额!');
			return false;
		}
		if(extractMoney % 100 != 0){
			alert('请输入100的倍数提现金额!');
			return false;
		}
		if(extractMoney < 100){
			alert('最低提现100以上!');
			return false;
		}
		
		if($('#dtype').val()=='Dynamic' &&  parseFloat($('#cashbussiness_balance1').val())<parseFloat($('#extractMoney').val())){
			 alert('提取失败,可提取金额超出!');
			 return false;
		}
		if($('#dtype').val()=='Static' &&  parseFloat($('#cashbussiness_balance2').val())<parseFloat($('#extractMoney').val())){
			 alert('提取失败,可提取金额超出!');
			 return false;
		}
		$('#cashBusinessForm').submit();
	}
	
	</script>


</body>
</html>